/**
 * @author：anlzou
 * @Date：Created in9:56 2021/4/19
 * @Github：https://github.com/anlzou
 * @Description：
 */
package com.anlzou.threads;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Threads4 implements Runnable{
    @Override
    public void run() {
        System.out.println("通过线程池+runnable实现多线程，名称："+Thread.currentThread().getName());
    }

    public void threadPool(){
        // 固定线程数大小
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        for(int i=0; i<10; i++){
            executorService.execute(new Threads4());
        }

        System.out.println("主线程名称:"+Thread.currentThread().getName());

        //关闭线程池
        executorService.shutdown();
    }
}
